package com.jackrain.nea.common;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.util.ReferenceUtil;
import com.jackrain.nea.web.QueryCmd;

import java.util.HashMap;

/**
 * @author wuwenxue
 * @date 2018/07/04
 **/
public class QueryDLUtil {

    @Reference(group = "dl",version = "8")
    private QueryCmd queryCmd;

    /**
     * 跨库查询
     *
     * @param tableName 表名
     * @param field     字段
     * @param whereJson 条件
     * @return hashmap
     */
    public static HashMap queryDL(String tableName, String field, JSONObject whereJson) {
        HashMap dlHashMap = new HashMap(16);
        dlHashMap.put("type", HashMap.class);
        dlHashMap.put("tableName", tableName);
        dlHashMap.put("fields", field);
        dlHashMap.put("whereKeys", whereJson);

        Object o = ReferenceUtil.refer(ApplicationContextHandle.getApplicationContext(),
                "com.jackrain.nea.web.QueryCmd",
                "dl", "8");
        HashMap result = (HashMap) ((QueryCmd) o).queryTable(dlHashMap);

//        JSONObject cpJson = new JSONObject(result);

        return result;
    }



}
